home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 7: Sunsite / Linux Cubed Series 7 - Sunsite Vol 1.iso / system / news / inn1.000 / inn1.4sec-linux-src.tar / inn / samples / scanlogs < prev    next >
Text File  |  1993-03-18  |  9KB  |  352 lines

  1. #! /bin/sh
  2. ##  $Revision: 1.21 $
  3. ##  Summarize INN log files.
  4. ##  Optional arguments:
  5. ##    norotate    Do not rotate logfiles
  6.  
  7. ##  =()<. @<_PATH_SHELLVARS>@>()=
  8. . /news/lib/innshellvars
  9.  
  10. ##  If you get an error from this line:
  11. ##    sh -c 'egrep "`ls /etc`" /dev/null'
  12. ##  then get a better egrep, like the FSF one.
  13.  
  14. ##  Directory where old log files are kept.
  15. OLD=${MOST_LOGS}/OLD
  16. ##  If you want to archive the active file, enable this line.
  17. ACTIVEFILE=${ACTIVE}
  18. ##  Number of lines of error in each category to report.
  19. TOP=${TOP-20}
  20. ##  NN log file.
  21. NN=${NEWSLIB}/nn/Log
  22. ##  Where nntpsend, if used, writes its log information.
  23. NNTPSEND=${MOST_LOGS}/nntpsend.log
  24. ##  Where news.daily places expire output, unless noexplog was used.
  25. EXPLOG=${MOST_LOGS}/expire.log
  26.  
  27. ##  If you divide your news syslog into separate files, list them here.
  28. SYSLOG_CRIT=${MOST_LOGS}/news.crit
  29. SYSLOG_ERR=${MOST_LOGS}/news.err
  30. SYSLOG_NOTICE=${MOST_LOGS}/news.notice
  31. SYSLOGS="${SYSLOG_CRIT} ${SYSLOG_ERR} ${SYSLOG_NOTICE}"
  32.  
  33. ##  Where tally control and unwanted processors are found.
  34. TALLY_CONTROL=${NEWSBIN}/tally.control
  35. TALLY_UNWANTED=${NEWSBIN}/tally.unwanted
  36. UNWANTED_LOG=${MOST_LOGS}/unwanted.log
  37. CONTROL_LOG=${MOST_LOGS}/control.log
  38. CONTROL_DATA=
  39. test -f ${MOST_LOGS}/newgroup.log && CONTROL_DATA=${MOST_LOGS}/newgroup.log
  40. test -f ${MOST_LOGS}/rmgroup.log \
  41.     && CONTROL_DATA="${CONTROL_DATA} ${MOST_LOGS}/rmgroup.log"
  42.  
  43. ##  Build up the list of log files to process.
  44. LOGS="${ERRLOG} ${EXPLOG} ${LOG} ${ACTIVEFILE} ${SYSLOGS} ${UNWANTED_LOG}"
  45. test -n "${NNTPSEND}" -a -f "${NNTPSEND}" && LOGS="${LOGS} ${NNTPSEND}"
  46. test -n "${CONTROL_DATA}" && LOGS="${LOGS} ${CONTROL_LOG}"
  47. for F in checkgroups default ihave newgroup rmgroup sendme \
  48.      sendsys senduuname version miscctl; do
  49.     test -f ${MOST_LOGS}/${F}.log && LOGS="${LOGS} ${MOST_LOGS}/${F}.log"
  50. done
  51.  
  52. PROGNAME=scanlogs
  53. LOCK=${LOCKS}/LOCK.${PROGNAME}
  54.  
  55. ##  Set defaults.
  56. ROTATE=true
  57.  
  58. ##  Parse JCL.
  59. for I
  60. do
  61.     case "X$I" in
  62.     Xnonn)
  63.     # Ignore this.
  64.     ;;
  65.     Xnorotate)
  66.     ROTATE=false
  67.     ;;
  68.     *)
  69.     echo "Unknown flag ${I}" 1>&2
  70.     exit 1
  71.     ;;
  72.     esac
  73. done
  74.  
  75. ##  Make sure every log exists.
  76. for F in ${LOGS} ; do
  77.     test ! -f ${F} && touch ${F}
  78. done
  79.  
  80. ##  Temporary files.
  81. T=${TMPDIR}/scan$$
  82. PROBS=${TMPDIR}/scanlog$$
  83. trap "rm -f ${T} ${PROBS}; exit 0" 0 1 2 3 15
  84.  
  85. ##  Rotate the logs?
  86. if ${ROTATE} ; then
  87.     ##  Lock out others.
  88.     shlock -p $$ -f ${LOCK} || {
  89.     echo "$0: Locked by `cat ${LOCK}`"
  90.     exit 1
  91.     }
  92.     trap "rm -f ${T} ${PROBS} ${LOCK}; exit 0" 1 2 3 15
  93.  
  94.     HERE=`pwd`
  95.     cd ${MOST_LOGS}
  96.  
  97.     ctlinnd -s pause "Flushing log and syslog files" 2>&1
  98.     ctlinnd -s flushlogs 2>&1 || {
  99.     echo 'Cannot flush logs.'
  100.     rm -f ${LOCK}
  101.     exit 1
  102.     }
  103.  
  104.     ##  Make sure these .old files exist, in case innd is down.
  105.     for F in ${LOG} ${ERRLOG} ${EXPLOG} ; do
  106.     if [ ! -f ${F}.old ]; then
  107.         rm -f ${F}.old
  108.         cp ${F} ${F}.old
  109.         cat /dev/null >${F}
  110.     fi
  111.     done
  112.  
  113.     ##  Copy syslog files, truncating old inode since syslog has it open.
  114.     for F in ${SYSLOGS}; do
  115.     rm -f ${F}.old
  116.     cp ${F} ${F}.old
  117.     cat /dev/null >${F}
  118.     done
  119.  
  120.     ##  Make a copy of the active file.
  121.     if [ -n ${ACTIVEFILE} ] ; then
  122.     BASE=`basename ${ACTIVEFILE}`
  123.     rm -f ${OLD}/${BASE}.old
  124.     cp ${ACTIVEFILE} ${OLD}/${BASE}.old
  125.     fi
  126.  
  127.     ##  These are live files, so use link rather than copy.
  128.     for F in ${NNTPSEND} ; do
  129.     if [ -f ${F} ]; then
  130.         rm -f ${F}.old ${F}.new
  131.         ln ${F} ${F}.old
  132.         touch ${F}.new
  133.         chmod 0660 ${F}.new
  134.         mv ${F}.new ${F}
  135.     fi
  136.     done
  137.  
  138.     ##  Tally control messages if we logged them.
  139.     test -n "${CONTROL_DATA}" && cat ${CONTROL_DATA} | ${TALLY_CONTROL}
  140.     ${TALLY_UNWANTED} <${LOG}.old
  141.  
  142.     ctlinnd -s go "Flushing log and syslog files" 2>&1
  143.  
  144.     cd ${OLD}
  145.     for F in ${LOGS}; do
  146.     ##  Process the current (just-flushed) log
  147.     BASE=`basename ${F}`
  148.     rm -f ${OLD}/${BASE}
  149.     case ${F} in
  150.     ${SYSLOG_CRIT}|${ERRLOG}|${EXPLOG}|${LOG}|${SYSLOG_NOTICE})
  151.         ##  Make a link that can be deleted (since if not rotating
  152.         ##  we delete the copy that is made in ${TMPDIR}).
  153.         mv ${F}.old ${OLD}/${BASE}
  154.         rm -f ${OLD}/${BASE}.0
  155.         ln ${OLD}/${BASE} ${OLD}/${BASE}.0
  156.         ;;
  157.     ${ACTIVEFILE})
  158.         mv ${BASE}.old ${OLD}/${BASE}
  159.         ;;
  160.     ${SYSLOG_ERR})
  161.         mv ${F}.old ${OLD}/${BASE}
  162.         ;;
  163.     *)
  164.         if [ -f ${F}.old ]; then
  165.         mv ${F}.old ${OLD}/${BASE}
  166.         else
  167.         rm -f ${OLD}/${BASE} ${F}.new
  168.         touch ${F}.new
  169.         chmod 0660 ${F}.new
  170.         ln ${F} ${OLD}/${BASE}
  171.         mv ${F}.new ${F}
  172.         fi
  173.         ;;
  174.     esac
  175.     done
  176.     cd ${HERE}
  177.  
  178.     ##  Truncate logs from send-nntp and/or send-uucp.
  179.     if [ -s ${MOST_LOGS}/send-nntp.log ] ; then
  180.     ${COMPRESS} <${MOST_LOGS}/send-nntp.log >${OLD}/send-nntp.1${Z}
  181.     cat /dev/null >${MOST_LOGS}/send-nntp.log
  182.     fi
  183.     if [ -s ${MOST_LOGS}/send-uucp.log ] ; then
  184.     ${COMPRESS} <${MOST_LOGS}/send-uucp.log >${OLD}/send-uucp.1${Z}
  185.     cat /dev/null >${MOST_LOGS}/send-uucp.log
  186.     fi
  187. else
  188.     ##  Don't use the real OLD directory, instead use TMPDIR
  189.     OLD=${TMPDIR}
  190.  
  191.     ##  Make a snapshot of what we need for below.
  192.     ctlinnd -s pause "Snapshot log and syslog files" 2>&1
  193.     for F in ${SYSLOG_CRIT} ${ERRLOG} ${EXPLOG} ${LOG} ${SYSLOG_NOTICE} ; do
  194.     BASE=`basename ${F}`
  195.     rm -f ${OLD}/${BASE}.0
  196.     cp ${F} ${OLD}/${BASE}.0
  197.     done
  198.     ctlinnd -s go "Snapshot log and syslog files" 2>&1
  199. fi
  200.  
  201. ##
  202. ##  We now (finally!) have copies of the log files where we need them.
  203. ##
  204.  
  205. ##  Display syslog critical messages.
  206. BASE=`basename ${SYSLOG_CRIT}`
  207. OLD_SYSLOG=${OLD}/${BASE}.0
  208. if [ -s ${OLD_SYSLOG} ] ; then
  209.     echo Syslog critical messages:
  210.     cat ${OLD_SYSLOG}
  211.     echo ---------
  212.     echo ''
  213. fi
  214. rm -f ${OLD_SYSLOG}
  215.  
  216. ##  Display error log.
  217. BASE=`basename ${ERRLOG}`
  218. OLD_ERRLOG=${OLD}/${BASE}.0
  219. if [ -s ${OLD_ERRLOG} ] ; then
  220.     echo Error log:
  221.     cat ${OLD_ERRLOG}
  222.     echo ---------
  223.     echo ''
  224. fi
  225. rm -f ${OLD_ERRLOG}
  226.  
  227. ##  Display expire log messages
  228. BASE=`basename ${EXPLOG}`
  229. OLD_EXPLOG=${OLD}/${BASE}.0
  230. if [ -s ${OLD_EXPLOG} ] ; then
  231.     echo Expire messages:
  232.     cat ${OLD_EXPLOG}
  233.     echo ---------
  234.     echo ''
  235. fi
  236. rm -f ${OLD_EXPLOG}
  237.  
  238. ##  Scan for various problems in articles we were offered or sent.
  239. BASE=`basename ${LOG}`
  240. OLD_LOG=${OLD}/${BASE}.0
  241. if [ -f ${OLD_LOG} ]; then
  242.     ${AWK} '$4 == "-" || $4 == "j" { print }' <${OLD_LOG} >${PROBS}
  243.  
  244.     ${AWK} '$4 == "-" { print $5; }' ${PROBS} \
  245.         | sort | uniq -c | sort -nr | ${SED} ${TOP}q >${T}
  246.     if [ -s ${T} ] ; then
  247.     echo Top ${TOP} sites sending bad articles:
  248.     cat ${T}
  249.     echo ''
  250.     fi
  251.  
  252.     ${AWK} '$4 == "j" { print $5; }' ${PROBS} \
  253.         | sort | uniq -c | sort -nr | ${SED} ${TOP}q >${T}
  254.     if [ -s ${T} ] ; then
  255.     echo Top ${TOP} sites sending junked "(unwanted)" articles:
  256.     cat ${T}
  257.     echo ''
  258.     fi
  259.  
  260.  
  261.     ${EGREP} '437 Unwanted distribution' ${PROBS} | ${SED} 's/.*"\(.*\)".*/\1/' \
  262.         | sort | uniq -c | sort -nr | ${SED} ${TOP}q >${T}
  263.     if [ -s ${T} ] ; then
  264.     echo Top ${TOP} unwanted distributions by number of articles:
  265.     cat ${T}
  266.     echo ''
  267.     fi
  268.  
  269.     ${EGREP} '437 Unapproved for' ${PROBS} | ${SED} 's/.*"\(.*\)".*/\1/' \
  270.         | sort | uniq -c | sort -nr | ${SED} ${TOP}q >${T}
  271.     if [ -s ${T} ] ; then
  272.     echo Top ${TOP} supposedly-moderated groups with unmoderated postings:
  273.     cat ${T}
  274.     echo ''
  275.     fi
  276.  
  277.     ${EGREP} '437 Unwanted newsgroup' ${PROBS} | ${SED} 's/.*"\(.*\)".*/\1/' \
  278.         | sort | uniq -c | sort -nr | ${SED} ${TOP}q >${T}
  279.     if [ -s ${T} ] ; then
  280.     echo Top ${TOP} unwanted newsgroups:
  281.     cat ${T}
  282.     echo ''
  283.     fi
  284.  
  285.     ##  Your egrep may complain about this regular expression being too long;
  286.     ##  if so, complain to your vendor and try GNU egrep.
  287.     P1='No body|EOF in headers|"Message-ID"|No colon-space in '
  288.     P2='Missing ".*" header|Linecount|Bad Date|Too old'
  289.     ${EGREP} "${P1}|${P2}" ${PROBS} \
  290.         | ${SED} -e 's/.*437 //' \
  291.         -e 's/Linecount.*/Linecount wrong/' -e 's/Too old.*/Too old/' \
  292.         | sort | uniq -c | sort -nr | ${SED} ${TOP}q >${T}
  293.     if [ -s ${T} ] ; then
  294.     echo Top ${TOP} general message problems:
  295.     cat ${T}
  296.     echo ''
  297.     fi
  298.  
  299.     ${EGREP} "${P1}|${P2}" ${PROBS} | ${AWK} '{print $5}' \
  300.         | sort | uniq -c | sort -nr | ${SED} ${TOP}q >${T}
  301.     if [ -s ${T} ] ; then
  302.     echo Top ${TOP} sites sending news with bad headers:
  303.     cat ${T}
  304.     echo ''
  305.     fi
  306.     rm -f ${PROBS}
  307. fi
  308. rm -f ${OLD_LOG}
  309.  
  310. ##  Summarize syslog information
  311. BASE=`basename ${SYSLOG_NOTICE}`
  312. OLD_SYSLOG=${OLD}/${BASE}.0
  313. if [ -s ${OLD_SYSLOG} ] ; then
  314.     echo Syslog summary:
  315.     ##  Portable work-around some debugging syslogs.
  316.     ${SED} -e 's/{news.[a-z]*} //' <${OLD_SYSLOG} | ${AWK} -f ${NEWSLIB}/innlog.awk
  317.     echo ---------
  318.     echo ''
  319. fi
  320. rm -f ${OLD_SYSLOG}
  321.  
  322. ##  Compress and rotate the logs.
  323. if ${ROTATE} ; then
  324.     cd ${OLD}
  325.     for F in ${LOGS} ; do
  326.     ##  Skip if file doesn't exist.
  327.     BASE=`basename ${F}`
  328.     test -f ${BASE} || continue
  329.  
  330.     ##  Compress the file.
  331.     ${COMPRESS} <${BASE} >${BASE}.0${Z} && rm -f ${BASE}
  332.     chmod 0440 ${BASE}.0${Z}
  333.  
  334.     ##  Do rotation.
  335.     EXT=${CYCLES}
  336.     rm -f ${BASE}.${CYCLES}${Z}
  337.     while [ ${EXT} -gt 0 ] ; do
  338.         NEXT=${EXT}
  339.         EXT=`expr ${EXT} - 1`
  340.         test -f ${BASE}.${EXT}${Z} \
  341.         && rm -f ${BASE}.${NEXT}${Z} \
  342.         && mv ${BASE}.${EXT}${Z} ${BASE}.${NEXT}${Z}
  343.     done
  344.     done
  345.  
  346.     ##  Remove lock.
  347.     rm -f ${LOCK}
  348. fi
  349.  
  350. ##  All done.
  351. exit 0
  352.